
package py.una.pol.raphapy.autoventas.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rafael E. Benegas
 */
@Entity
@Table(name = "tipo_persona")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TipoPersona.findAll", query = "SELECT t FROM TipoPersona t"),
    @NamedQuery(name = "TipoPersona.findByCodTipPer", query = "SELECT t FROM TipoPersona t WHERE t.codTipPer = :codTipPer"),
    @NamedQuery(name = "TipoPersona.findByDesTipPer", query = "SELECT t FROM TipoPersona t WHERE t.desTipPer = :desTipPer")})
public class TipoPersona implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Size(min = 1, max = 4)
    @Column(name = "cod_tip_per")
    private String codTipPer;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "des_tip_per")
    private String desTipPer;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codTipPer")
    private Collection<Persona> personaCollection;

    public TipoPersona() {
    }

    public TipoPersona(String codTipPer) {
        this.codTipPer = codTipPer;
    }

    public TipoPersona(String codTipPer, String desTipPer) {
        this.codTipPer = codTipPer;
        this.desTipPer = desTipPer;
    }

    public String getCodTipPer() {
        return codTipPer;
    }

    public void setCodTipPer(String codTipPer) {
        this.codTipPer = codTipPer;
    }

    public String getDesTipPer() {
        return desTipPer;
    }

    public void setDesTipPer(String desTipPer) {
        this.desTipPer = desTipPer;
    }

    @XmlTransient
    public Collection<Persona> getPersonaCollection() {
        return personaCollection;
    }

    public void setPersonaCollection(Collection<Persona> personaCollection) {
        this.personaCollection = personaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (codTipPer != null ? codTipPer.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        
        if (!(object instanceof TipoPersona)) {
            return false;
        }
        TipoPersona other = (TipoPersona) object;
        if ((this.codTipPer == null && other.codTipPer != null) || (this.codTipPer != null && !this.codTipPer.equals(other.codTipPer))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.desTipPer;
    }
    
}
